package com.jushu.storbox.view.dialog;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.jushu.storbox.R;
import com.jushu.storbox.ShareDriveApplication;
import com.jushu.storbox.actions.FileAction;
import com.jushu.storbox.actions.FolderAction;
import com.jushu.storbox.constant.UiConstant;
import com.jushu.storbox.entities.FileFolderInfo;
import com.jushu.storbox.entities.FileType;
import com.jushu.storbox.util.LogUtil;
import com.jushu.storbox.util.NameUtils;
import com.jushu.storbox.util.PublicTools;
import com.huawei.sharedrive.sdk.android.exception.ClientException;
import com.huawei.sharedrive.sdk.android.model.request.FolderCreateRequest;
import com.huawei.sharedrive.sdk.android.service.handler.AsyncTaskHandler;

public class DeleteFileDialog {

	public void delete(final Activity activity, final String ownerId, final FileFolderInfo fileFolderInfo, final Handler msgHandler
			,final ProgressDialog loading_ll){
			
		final ClouddriveDialog delete = new ClouddriveDialog(activity, R.style.dialog_upload,
                R.layout.dialog_filedelete);
            View conventView = delete.getConventView();
            Button dialog_cancal = (Button) conventView.findViewById(R.id.dialog_add_file_cancal_bt);
            WindowManager windowManager =activity.getWindowManager();
            Display display=windowManager.getDefaultDisplay();
    		delete.setWidth(display.getWidth());
    		delete.setPosition(Gravity.CENTER_HORIZONTAL,Gravity.CENTER_VERTICAL);
    		Button dialog_OK = (Button) conventView.findViewById(R.id.dialog_add_file_ok_bt);
            
            TextView dialog_prompt_tv = (TextView) conventView.findViewById(R.id.dialog_prompt_tv);
            dialog_prompt_tv.setText(activity.getString(R.string.allfile_confirm_delete_filefolder));
            dialog_cancal.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    delete.dismiss();
                }
            });
            
            dialog_OK.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    delete.dismiss();
                    if (!loading_ll.isShowing())
                    {
                        loading_ll.show();
                    }
                    if (FileType.File.value() == fileFolderInfo.getIsFile()){
                    	new FileAction().deleteFile(activity, fileFolderInfo, msgHandler);
                    }else{
                		new FolderAction().deleteFolder(activity, fileFolderInfo, msgHandler);
                    }
                }
            });
            
            delete.show();
        
	}
	
}
